<template>
  <div class="icons">
      <swiper :options="swiperOptions">
          <swiper-slide v-for="(page,index) of pages" :key="index">
            <div class="icon" v-for="item of page" :key='item.id'>
            <div class="icon-img" >
                <img class="icon-img-cotent" :src="item.imgUrl" alt="" />
            </div>
            <p class="icon-desc">{{item.desc}}</p>
            </div>
          </swiper-slide>
      </swiper>
  </div>
</template>
<script>
export default {
  name: "HomeIcons",
  data () {
    return {
       swiperOptions: {
         autoplay: false
       }
    }
  },
  props: {
      list: Array
  },
  computed : {
      pages() {
          const pages = []
          this.list.forEach((item,index)=>{
              const page = Math.floor(index/8)
              if (!pages[page]) {
                  pages[page] = []
              }
              pages[page].push(item)
          })
          return pages
      }
  }
};
</script>
<style scoped>
.icons >>> .swiper-container {
  height: 0;
  padding-bottom: 50%;
  /* background: green; */
}
.icon {
  position: relative;
  overflow: hidden;
  float: left;
  height: 0;
  width: 25%;
  padding-bottom: 25%;
  margin-top: 10px;
  /* background: red; */
}
.icon-img {
  position: absolute;
  right: 0;
  left: 0;
  top: 0;
  bottom: 22px;
  box-sizing: border-box;
  padding: 5px;
  /* background: blue; */
}
.icon-img-cotent {
    display: block;
   height: 100%;
   margin: 0 auto;
}
.icon-desc {
   position: absolute;
   left: 0;
   right: 0;
   bottom: 0px;
   height: 22px;
   line-height: 22px;
   text-align: center;
   color: #ccc;
   overflow: hidden;
   white-space: nowrap;
   text-overflow: ellipsis;
}
</style>